package com.jiangjiang.eshop.wms.controller;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiangjiang.eshop.wms.constant.SaleDeliveryOrderApproveResult;
import com.jiangjiang.eshop.wms.constant.SaleDeliveryOrderStatus;
import com.jiangjiang.eshop.wms.domain.SaleDeliveryOrderEntity;
import com.jiangjiang.eshop.wms.dto.SaleDeliveryOrderApproveDTO;
import com.jiangjiang.eshop.wms.dto.SaleDeliveryOrderDTO;
import com.jiangjiang.eshop.wms.dto.SaleDeliveryOrderQuery;
import com.jiangjiang.eshop.wms.dto.SaleDeliveryOrderUpdateQuery;
import com.jiangjiang.eshop.wms.service.SaleDeliveryOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @Author Jianghaowen
 * @Date 2021/9/17
 * @Description: TODO
 * @Version V1.0
 **/
@Slf4j
@RestController
@RequestMapping("/sale/delivery/order")
public class SaleDeliveryOrderController {

    @Autowired
    private SaleDeliveryOrderService saleDeliveryOrderService;



    /**
     *
     * @param query
     * @return
     */
    @PostMapping("/queryForPage")
    public Page<SaleDeliveryOrderDTO> queryForPage(@RequestBody SaleDeliveryOrderQuery query){
        try {
           return saleDeliveryOrderService.queryForPage(query);
        }catch (Exception e){
            log.warn("SaleDeliveryOrderController queryForPage error",e);
        }
        return null;
    }



    /**
     * 根据销售出库单id查询销售出库单全量数据
     *
     * @param id 销售出库单id
     * @return 查询结果
     */
    @GetMapping("/queryById/{id}")
    public SaleDeliveryOrderDTO queryById(@PathVariable("id") Long id) {
        try {
            return saleDeliveryOrderService.queryById(id);
        }catch (Exception e){
            log.warn("SaleDeliveryOrderController queryById error",e);
        }
        return null;
    }

    /**
     * 更新销售出库单发货时间
     *
     * @param query
     * @return
     */
    @PostMapping("/updateDeliveryTime")
    public Boolean updateDeliveryTime(@RequestBody SaleDeliveryOrderUpdateQuery query) {
        try {
            return saleDeliveryOrderService.updateDeliveryTime(query.getSaleDeliveryOrderId(), query.getDeliveryTime());
        }catch (Exception e){
            log.warn("SaleDeliveryOrderController updateDeliveryTime error",e);
        }
        return false;
    }


    /**
     * 对销售出库单提交审核
     *
     * @param id 销售出库单id
     * @return 处理结果
     */
    @GetMapping("/submitApprove/{id}")
    public Boolean submitApprove(@PathVariable("id") Long id) {
        try {
            return saleDeliveryOrderService.submitApprove(id);
        }catch (Exception e){
            log.warn("SaleDeliveryOrderController updateDeliveryTime error",e);
        }
        return false;
    }


    /**
     * 对销售出库单提交审核
     *
     * @param id 销售出库单id
     * @return 处理结果
     */
    @PostMapping("/approve")
    public Boolean approve(@RequestBody SaleDeliveryOrderApproveDTO dto) {
        try {
            return saleDeliveryOrderService.approve(dto.getSaleDeliveryOrderId(), dto.getApproveResult());
        }catch (Exception e){
            log.warn("SaleDeliveryOrderController approve e",e);
        }
        return false;
    }
}
